using System;
using System.Collections.Generic;
using System.Text;

namespace Accio {
	class Log {
		static Log(){
			//System.IO.File.Delete("log.txt");
		}
		public static void Error(string text){
			DoLog(text, Levels.ERROR);
		}
		public static void Info(string text) {
			DoLog(text, Levels.INFO);
		}
		public static void Debug(string text) {
			DoLog(text, Levels.DEBUG);
		}
		private static void DoLog(string text, Levels textLevel) {
			if(textLevel < level) {
				return;
			}
			string decoratedText = "";
			decoratedText += level.ToString() + ":";
			decoratedText += "[" + System.DateTime.Now + "]========================\n"
				+ text + "\n";
			while(true) {
				try {
					System.IO.File.AppendAllText("log.txt", decoratedText);
					break;
				}
				catch(System.IO.IOException) {
					// Log file is been used by others.
				}
			}
		}
		public enum Levels{
			DEBUG = 0,
			INFO = 10,
			ERROR = 20
		}
		private static Levels Level {
			get {
				return level;
			}
			set {
				level = value;
			}
		}
		private static Levels level = Levels.DEBUG;
	}
}
